package com.ruoyi.project.jiaqin.vipconfig.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.jiaqin.vipconfig.domain.VipConfig;
import com.ruoyi.project.jiaqin.vipconfig.service.IVipConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员年限、价格配置Controller
 *
 * @author LCL
 * @date 2021-11-17
 */
@Controller
@RequestMapping("/jiaqin/vipconfig")
public class VipConfigController extends BaseController
{
    private String prefix = "jiaqin/vipconfig";

    @Autowired
    private IVipConfigService vipConfigService;

    @RequiresPermissions("jiaqin:vipconfig:view")
    @GetMapping()
    public String vipconfig()
    {
        return prefix + "/vipconfig";
    }

    /**
     * 查询会员年限、价格配置列表
     */
    @RequiresPermissions("jiaqin:vipconfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VipConfig vipConfig)
    {
        startPage();
        List<VipConfig> list = vipConfigService.selectVipConfigList(vipConfig);
        return getDataTable(list);
    }

    /**
     * 导出会员年限、价格配置列表
     */
    @RequiresPermissions("jiaqin:vipconfig:export")
    @Log(title = "会员年限、价格配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VipConfig vipConfig)
    {
        List<VipConfig> list = vipConfigService.selectVipConfigList(vipConfig);
        ExcelUtil<VipConfig> util = new ExcelUtil<VipConfig>(VipConfig.class);
        return util.exportExcel(list, "vipconfig");
    }

    /**
     * 新增会员年限、价格配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会员年限、价格配置
     */
    @RequiresPermissions("jiaqin:vipconfig:add")
    @Log(title = "会员年限、价格配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VipConfig vipConfig)
    {
        return toAjax(vipConfigService.insertVipConfig(vipConfig));
    }

    /**
     * 修改会员年限、价格配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        VipConfig vipConfig = vipConfigService.selectVipConfigById(id);
        mmap.put("vipConfig", vipConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员年限、价格配置
     */
    @RequiresPermissions("jiaqin:vipconfig:edit")
    @Log(title = "会员年限、价格配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VipConfig vipConfig)
    {
        return toAjax(vipConfigService.updateVipConfig(vipConfig));
    }

    /**
     * 删除会员年限、价格配置
     */
    @RequiresPermissions("jiaqin:vipconfig:remove")
    @Log(title = "会员年限、价格配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vipConfigService.deleteVipConfigByIds(ids));
    }
}
